<template>
    <!-- 评论弹窗 -->
    <van-popup v-model="ispopupshow" @click-overlay="hidepub" position="bottom" :style="{display:'flex' }">
        <van-field
            v-model="msg"
            v-show="ispopupshow"
            rows="4"
            autosize
            color="#ccc"
            type="textarea"
            placeholder="请输入内容"
        >
        <van-button style="flex-shirk:0;padding:0 .4rem;"  slot="button" color="#ff6034" round size='small' :disabled='!msg.length' @click="publishfun()">发布</van-button>
        </van-field>
        <!-- <van-button style="flex-shirk:0" type="default" round size='small'>发布</van-button> -->
    </van-popup>
</template>

<script>
import {publishcom} from '@/api/article'
export default {
    components: {},
    props: {
        type:{
            type:String,
            required:true,
            default:'comment'
        },
        message:{
            type:String,
            default:'',
        },
        popupshow:{
            type:Boolean,
        },
        target:{
            type:String,
            default:''
        },
        artid:{
            type:String,
            default:''
        },
        comlist:{
            type:Array,
            default:[]
        },
        //修改评论回复数量用的
        theCommentData:{
            type:Object,
            default:()=>{}
        }
    },
    data() {
        return {
           msg:'',
           ispopupshow:false
        };
    },
    watch: {
        popupshow(val) {
            console.log(val)
            if(this.message){
                this.msg = this.message
            }else{
                this.msg = ''
            }
            this.ispopupshow=val
            console.log(this.msg)
        }
    },
    computed: {},
    methods: {
        //发布评论
        async publishfun(){
            const pub_data={target:this.target,content:this.msg}
            try{
                if(this.type=='reply'){
                   pub_data.art_id=this.artid
                }
                const {data}=await publishcom(pub_data)
                if(data.message=='OK'){
                    this.msg=''
                    this.comlist.unshift(data.data.new_obj)
                    this.$bus.$emit('chReplyNum')
                    this.$toast('发布成功')
                    if(this.type=='reply'){
                        this.theCommentData.reply_count+=1
                    }
                }else{
                    this.$toast('发布失败')
                }
                this.hidepub()
            }
            catch(err){
                this.$toast('发布失败')
                console.log(err,'error')
            }
        },
        hidepub(){
            this.msg=''
            this.$emit('hidepub')
        }
    },
    computed:{
        
    },
    created() {
        console.log(this.message)
    },
    mounted() {}
};
</script>
<style lang="less" scoped>
</style>